import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '主页', icon: 'dashboard' }
    }]
  },
  {
    path: '/library',
    component: Layout,
    redirect: '/example/table',
    name: 'Library',
    meta: {title: '图书馆管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'message',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Message',
        meta: {title: '留言管理', icon: 'el-icon-s-help'},
        children: [
          {
            path: '/messageadd',
            name: 'messageadd',
            component: () => import('@/views/library/message/MessageAdd'),
            meta: {title: '留言新增', icon: 'el-icon-plus'}
          },
          {
            path: '/messagelist',
            name: 'messagelist',
            component: () => import('@/views/library/message/MessageList'),
            meta: {title: '留言列表', icon: 'el-icon-s-order'}
          },
          {
            path: '/messageupdate',
            name: 'messageupdate',
            component: () => import('@/views/library/message/MessageUpdate'),
            meta: {title: '留言修改', icon: 'table'},
            hidden: true
          }
        ]
      },
      {
        path: 'admin',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Admin',
        meta: {title: '管理员管理', icon: 'el-icon-s-help'},
        children: [
          {
            path: '/adminadd',
            name: 'adminadd',
            component: () => import('@/views/library/administrator/AdminAdd'),
            meta: {title: '管理员新增', icon: 'el-icon-plus'}
          },
          {
            path: '/adminlist',
            name: 'adminlist',
            component: () => import('@/views/library/administrator/AdminList'),
            meta: {title: '管理员列表', icon: 'el-icon-s-order'}
          },
          {
            path: '/adminupdate',
            name: 'adminupdate',
            component: () => import('@/views/library/administrator/AdminUpdate'),
            meta: {title: '管理员修改', icon: 'table'},
            hidden: true
          }
        ]
      },
      {
        path: '/book',
        component: () => import('@/views/nested/menu1/index'),
        redirect: '/book/table',
        name: 'Book',
        meta: {title: '图书管理', icon: 'el-icon-s-help'},
        children: [
          {
            path: '/bookadd',
            name: 'bookadd',
            component: () => import('@/views/library/book/BookAdd'),
            meta: {title: '图书新增', icon: 'el-icon-plus'}
          },
          {
            path: '/booklist',
            name: 'booklist',
            component: () => import('@/views/library/book/BookList'),
            meta: {title: '图书列表', icon: 'el-icon-s-order'}
          },
          {
            path: '/bookecharts',
            name: 'bookecharts',
            component: () => import('@/views/library/book/BookEchart'),
            meta: {title: '图书统计', icon: 'el-icon-s-order'}
          },
          {
            path: '/bookupdate',
            component: () => import('@/views/library/book/BookUpdate'),
            meta: {title: '图书修改', icon: 'table'},
            hidden: true
          },
        ]
      },
      {
        path: '/announcement',
        component: () => import('@/views/nested/menu1/index'),
        redirect: '/announcement/table',
        name: 'Announcement',
        meta: {title: '公告管理', icon: 'el-icon-s-help'},
        children: [
          {
            path: '/announcementadd',
            name: 'announcementadd',
            component: () => import('@/views/library/announcement/AnnouncementAdd'),
            meta: {title: '公告新增', icon: 'table'}
          },
          {
            path: '/announcementlist',
            name: 'announcementlist',
            component: () => import('@/views/library/announcement/AnnouncementList'),
            meta: {title: '公告列表', icon: 'table'}
          },
          {
            path: '/announcementupdate',
            name: 'announcementupdate',
            component: () => import('@/views/library/announcement/AnnouncementUpdate'),
            meta: {title: '公告修改', icon: 'table'},
            hidden: true
          }
        ]
      },
      {
        path: '/category',
        component: () => import('@/views/nested/menu1/index'),
        redirect: '/category/table',
        name: 'Category',
        meta: {title: '类别管理', icon: 'el-icon-s-help'},
        children: [
          {
            path: '/categoryadd',
            name: 'categoryadd',
            component: () => import('@/views/library/category/CategoryAdd'),
            meta: {title: '类别新增', icon: 'table'}
          },
          {
            path: '/categorylist',
            name: 'categorylist',
            component: () => import('@/views/library/category/CategoryList'),
            meta: {title: '类别列表', icon: 'table'}
          },
          {
            path: '/categoryupdate',
            name: 'categoryupdate',
            component: () => import('@/views/library/category/CategoryUpdate'),
            meta: {title: '类别修改', icon: 'table'},
            hidden: true
          }
        ]
      },
      {
        path: '/rule',
        component: () => import('@/views/nested/menu1/index'),
        redirect: '/rule/table',
        name: 'Rule',
        meta: {title: '规则管理', icon: 'el-icon-s-help'},
        children: [
          {
            path: '/ruleadd',
            name: 'ruleadd',
            component: () => import('@/views/library/rule/RuleAdd'),
            meta: {title: '规则新增', icon: 'table'}
          },
          {
            path: '/rulelist',
            name: 'rulelist',
            component: () => import('@/views/library/rule/RuleList'),
            meta: {title: '规则列表', icon: 'table'}
          },
          {
            path: '/ruleupdate',
            name: 'ruleupdate',
            component: () => import('@/views/library/rule/RuleUpdate'),
            meta: {title: '规则修改', icon: 'table'},
            hidden: true
          }
        ]
      },
      {
        path: '/record',
        component: () => import('@/views/nested/menu1/index'),
        redirect: '/record/table',
        name: 'Record',
        meta: {title: '借阅记录管理', icon: 'el-icon-s-help'},
        children: [
          {
            path: '/recordadd',
            name: 'recordadd',
            component: () => import('@/views/library/record/RecordAdd'),
            meta: {title: '借阅记录新增', icon: 'el-icon-plus'}
          },
          {
            path: '/recordlist',
            name: 'recordlist',
            component: () => import('@/views/library/record/RecordList'),
            meta: {title: '借阅列表', icon: 'el-icon-s-order'}
          },
          {
            path: '/recordecharts',
            name: 'recordecharts',
            component: () => import('@/views/library/record/RecordEcharts'),
            meta: {title: '借阅统计', icon: 'el-icon-s-order'}
          },
          {
            path: '/recordupdate',
            component: () => import('@/views/library/record/RecordUpdate'),
            meta: {title: '借阅记录修改', icon: 'table'},
            hidden: true
          },
        ]
      },
      {
        path: '/card',
        component: () => import('@/views/nested/menu1/index'),
        redirect: '/card/table',
        name: 'Card',
        meta: {title: '借阅卡管理', icon: 'el-icon-s-help'},
        children: [
          {
            path: '/cardadd',
            name: 'cardadd',
            component: () => import('@/views/library/card/CardAdd'),
            meta: {title: '借阅卡新增', icon: 'el-icon-plus'}
          },
          {
            path: '/cardlist',
            name: 'cardlist',
            component: () => import('@/views/library/card/CardList'),
            meta: {title: '借阅卡列表', icon: 'el-icon-s-order'}
          },
          {
            path: '/cardupdate',
            component: () => import('@/views/library/card/CardUpdate'),
            meta: {title: '借阅卡修改', icon: 'table'},
            hidden: true
          }
        ]
      },
    ]
  },
  {
    path: '/teacher',
    component: Layout,
    redirect: '/teacher/table',
    name: 'Teacher',
    meta: {title: '教师管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/teacheradd',
        name: 'teacheradd',
        component: () => import('@/views/edu/teacher/TeacherAdd'),
        meta: {title: '教师新增', icon: 'el-icon-plus'}
      },
      {
        path: '/teacherlist',
        name: 'teacherlist',
        component: () => import('@/views/edu/teacher/TeacherList'),
        meta: {title: '教师列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/teacherchart',
        name: 'teacherchart',
        component: () => import('@/views/edu/teacher/TeacherChart'),
        meta: {title: '教师统计', icon: 'el-icon-s-order'}
      },
      {
        path: '/teacherupdate',
        component: () => import('@/views/edu/teacher/TeacherUpdate'),
        meta: {title: '教师修改', icon: 'table'},
        hidden: true
      },
      {
        path: '/gcourseadd',
        name: 'gcourseadd',
        component: () => import('@/views/edu/teacher/GCourseAdd'),
        meta: {title: '授课新增', icon: 'el-icon-plus'}
      },
      {
        path: '/gcourselist',
        name: 'gcourselist',
        component: () => import('@/views/edu/teacher/GCourseList'),
        meta: {title: '授课列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/gcourseupdate',
        component: () => import('@/views/edu/teacher/GCourseUpdate'),
        meta: {title: '授课修改', icon: 'table'},
        hidden: true
      }
    ]
  },
  {
    path: '/class',
    component: Layout,
    redirect: '/class/table',
    name: 'Class',
    meta: {title: '班级管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/classadd',
        name: 'classadd',
        component: () => import('@/views/edu/tclass/TclassAdd'),
        meta: {title: '班级新增', icon: 'el-icon-plus'}
      },
      {
        path: '/classlist',
        name: 'classlist',
        component: () => import('@/views/edu/tclass/TclassList'),
        meta: {title: '班级列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/classchart',
        name: 'classchart',
        component: () => import('@/views/edu/tclass/TclassEcharts'),
        meta: {title: '班级统计', icon: 'el-icon-s-order'}
      },
      {
        path: '/classupdate',
        component: () => import('@/views/edu/tclass/TclassUpdate'),
        meta: {title: '班级修改', icon: 'table'},
        hidden: true
      }
    ]
  },
  {
    path: '/student',
    component: Layout,
    redirect: '/student/table',
    name: 'Student',
    meta: {title: '学生管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/studentadd',
        name: 'studentadd',
        component: () => import('@/views/edu/student/StudentAdd'),
        meta: {title: '学生新增', icon: 'el-icon-plus'}
      },
      {
        path: '/studentlist',
        name: 'studentlist',
        component: () => import('@/views/edu/student/StudentList'),
        meta: {title: '学生列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/studentupdate',
        component: () => import('@/views/edu/student/StudentUpdate'),
        meta: {title: '学生修改', icon: 'table'},
        hidden: true
      },
    ]
  },
  {
    path: '/course',
    component: Layout,
    redirect: '/course/table',
    name: 'Course',
    meta: {title: '课程管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/courseadd',
        name: 'courseadd',
        component: () => import('@/views/edu/course/CourseAdd'),
        meta: {title: '课程新增', icon: 'el-icon-plus'}
      },
      {
        path: '/courselist',
        name: 'courselist',
        component: () => import('@/views/edu/course/CourseList'),
        meta: {title: '课程列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/courseupdate',
        name: 'courseupdate',
        component: () => import('@/views/edu/course/CourseUpdate'),
        meta: {title: '课程修改', icon: 'table'},
        hidden: true
      }
    ]
  },
  {
    path: '/new',
    component: Layout,
    redirect: '/new/table',
    name: 'New',
    meta: {title: '新闻管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/newadd',
        name: 'newadd',
        component: () => import('@/views/news/NewsAdd'),
        meta: {title: '新闻新增', icon: 'el-icon-plus'}
      },
      {
        path: '/newlist',
        name: 'newlist',
        component: () => import('@/views/news/NewsList'),
        meta: {title: '新闻列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/newupdate',
        component: () => import('@/views/news/NewsUpdate'),
        meta: {title: '新闻修改', icon: 'table'},
        hidden: true
      },
      {
        path: '/authoradd',
        name: 'authoradd',
        component: () => import('@/views/news/AuthorAdd'),
        meta: {title: '作者新增', icon: 'table'}
      },
      {
        path: '/authorlist',
        name: 'authorlist',
        component: () => import('@/views/news/AuthorList'),
        meta: {title: '作者列表', icon: 'table'}
      },
      {
        path: '/authorecharts',
        name: 'authorecharts',
        component: () => import('@/views/news/AuthorEcharts'),
        meta: { title: '作者统计', icon: 'table' }
      },
      {
        path: '/authorupdate',
        component: () => import('@/views/news/AuthorUpdate'),
        meta: {title: '作者修改', icon: 'table'},
        hidden: true
      },{
        path: '/contextadd',
        name: 'contextadd',
        component: () => import('@/views/news/ContextAdd'),
        meta: {title: '评论新增', icon: 'el-icon-plus'}
      },
      {
        path: '/contextlist',
        name: 'contextlist',
        component: () => import('@/views/news/ContextList'),
        meta: {title: '评论列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/contextupdate',
        name: 'contextupdate',
        component: () => import('@/views/news/ContextUpdate'),
        meta: {title: '评论列表', icon: 'el-icon-s-order'},
        hidden:'true'
      }
    ]
  },
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: 'Nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: 'menu2' }
      }
    ]
  },
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
  mode:'hash'
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
